package com.zy.explore.db.infrastructure.plugins.multidbsupport.sqlchange.function;

import com.zy.explore.db.infrastructure.plugins.multidbsupport.sqlchange.base.SqlOper;
import com.zy.explore.db.infrastructure.plugins.multidbsupport.sqlchange.limit.SqlLimitTest;

import java.util.List;


/**
 * sql 方法替换测试
 *
 * @author xiayd
 */
public class SqlFunctionTest {

    public static void main(String[] args) {
        String sql = "";
        // sql += "select\n";
        // sql += "*\n";
        // sql += ",(SELECT group_concat(organ_name) FROM sys_organ o WHERE o.id=s.user_baid) AS baName,\n";
        // sql += "(SELECT\n";
        // sql += "ifnull(organ_name,'-') FROM sys_organ o WHERE o.id=s.user_bapid) AS bapName\n";
        // sql += "from sys_user s\n";
        // sql += "WHERE 1=1\n";
        // sql += "    AND (user_name\n";
        // sql += "    LIKE concat(  '%'  ,  ?  ,  '%'  ) or user_login_name\n";
        // sql += "   LIKE concat('%',concat(1234,'%'))\n";
        //
        // sql += " and sysdata( ) < ?\n";
        // sql += " and to_char('') < ?\n";
        // sql += " and to_char(concat(  '%'  ,  ?  ,  '%'  )) < ?\n";
        // sql += " and max(a.persont) + 0.5 < ?\n";
        // sql += " and max(a.persont + 0.5+(2*3),123) < ?\n";
        // sql += " and date_format(fb.start_time,'%Y-%m-%d') > '2021-01-01'\n";
        // sql += " and DATE_FORMAT \n (am.create_date,\n'%Y-%m-%d') BETWEEN DATE_FORMAT(#{startTime},'%Y-%m-%d') AND DATE_FORMAT(#{endTime},'%Y-%m-%d')\n";
        //
        // sql += " and CAST(a.num_value as DECIMAL) > 10";

        sql = "SELECT \r\n" +
                "        *\r\n" +
                "FROM \r\n" +
                "        t_daportal_borrow_record\r\n" +
                "WHERE \r\n" +
                "        datediff( now(), to_date(borrow_end_time, 'yyyy-mm-dd') ) > 0\r\n" +
                "    \r\n" +
                "order by \r\n" +
                "        create_date desc";


        System.out.println(sql);
        System.out.println("===============================");
        AbstractFunChangeFactory changeFactory = new DMFunChangeFactory();
        List<SqlOper> sqlOperList = SqlFunctionUtils.find(sql, changeFactory);
        System.out.println("===============================");

        System.out.println(SqlLimitTest.change(sql, sqlOperList));
    }


}
